package net.huashitong.ssydt.provider.money.service;

import net.huashitong.ssydt.PaginationResult;
import net.huashitong.ssydt.money.entity.SsMoneyOrder;
import net.huashitong.ssydt.money.entity.vo.SsMoneyOrderQueryInVO;
import net.huashitong.ssydt.provider.money.mapper.SsMoneyOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author huiyang.yu
 */
@Service
@Transactional
public class SsMoneyOrderServiceImpl implements SsMoneyOrderService {

    private SsMoneyOrderMapper mapper;

    @Autowired
    public SsMoneyOrderServiceImpl(SsMoneyOrderMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void save(SsMoneyOrder ssMoneyOrder) {
        mapper.save(ssMoneyOrder);
    }

    @Override
    public SsMoneyOrder getByOrderId(String orderId) {
        return mapper.getByOrderId(orderId);
    }

    @Override
    public void update(SsMoneyOrder ssMoneyOrder) {
        mapper.updateByPrimaryKeySelective(ssMoneyOrder);
    }

	@Override
	public PaginationResult<SsMoneyOrder> paginationQuery(SsMoneyOrderQueryInVO ssMoneyOrderQueryInVO) {
		PaginationResult result = new PaginationResult();
		result.setPageNumber(ssMoneyOrderQueryInVO.getPageNumber());
		result.setPageSize(ssMoneyOrderQueryInVO.getPageSize());

		// 查询记录总数
		int total = mapper.queryCount(ssMoneyOrderQueryInVO);
		result.setPageRecords(total);

		if (total == 0) {
			result.setList(new ArrayList());
		} else {
			// 查询当前页记录
			List<SsMoneyOrder> list = mapper.query(ssMoneyOrderQueryInVO);
			result.setList(list);
		}
		return result;
	}
}
